package com.vidyu.datalayer.dataaccesscomponents.impl;

import com.vidyu.businesslayer.businessentities.UserInProject;
import com.vidyu.datalayer.dataaccesscomponents.UserInProjectDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: eyalsa
 * Date: 28/02/12
 * Time: 14:38
 * Implementation Dao object for ContractorDao
 */

@SuppressWarnings({"unchecked", "UnusedDeclaration"})
@Repository("userInProjectDao")
public class UserInProjectDaoImpl extends BaseDaoImpl implements UserInProjectDao {

    @Autowired
    private HibernateTemplate template;

    @Override
    @Transactional(readOnly = false, propagation = Propagation.NESTED)
    public long save(UserInProject userInProject){
        return ((Long) template.save(userInProject));
    }

    @Override
    @Transactional(readOnly = false, propagation = Propagation.NESTED)
    public void update(UserInProject userInProject){
        template.update(userInProject);
    }


    @Override
    public UserInProject findById(long id) {
        return template.get(UserInProject.class, id);
    }




    @Override
    public List<UserInProject> getUsersInProjectByStatus(long projectId, UserInProject.ProjectStatus status){
        List<UserInProject> userInProjectList = this.findByNamedQuery("getUsersInProjectByStatus", projectId, status);
        if (userInProjectList.isEmpty()) {
            return null;
        }
        return userInProjectList;
    }
}
